//
//  HMBaseTableViewController.swift
//  HMWeibo1
//
//  Created by liGordon on 16/4/9.
//  Copyright © 2016年 lifuli. All rights reserved.
//

import UIKit

class HMBaseTableViewController: UITableViewController {

    // 用户是否登录
    var userLogin = HMUserAccountViewModel.sharedInstance.userLogin
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    
    //Mark: - 按钮点击事件
    @objc private func didClickRegister() {
        print("didClickRegister")
    }
    
    @objc private func didClickLogin() {
        print("didClickLogin")
    }
    
    //Mark: - 代理方法
    // 实现代理方法
    
    func visitorViewDidClickRegisterButton(visitorView visitorView: UIView) {
        print("visitorViewDidClickRegisterButton")
    }
    
    func visitorViewDidClickLoginButton(visitorView visitorView: UIView) {
        print("visitorViewDidClicLoginButton")

    }

    
    //Mark: - 私有方法
    // 设置访客视图
    private func setupVisitorView() {
        view = visitorView
        
        visitorView.delegate = self
        
        if self is HMHomeViewController {
            visitorView.startRotation()
        }else if self is HMMessageViewController {
            visitorView.setupVisitorViewInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is HMDiscoverTableViewController {
                     visitorView.setupVisitorViewInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is HMProfileViewController {
             visitorView.setupVisitorViewInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }

    // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("visitorViewDidClickRegisterButton"))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("visitorViewDidClickLoginButton"))
    }
    
    //Mark: - 懒加载
    lazy var visitorView: HMVisitorView = HMVisitorView()
    
    
}
    //扩展和OC的分类很像  只能扩展方法 可以对对象实现协议  好处方便管理代码
extension HMBaseTableViewController: HMVisitorViewDelegate {
        func visitorViewDidClickRegisterButton() {
            print("visitorViewDidClickRegisterButton")
        }
        func visitorViewDidClickLoginButton() {
           
            let oauthVC = HMOauthViewController()
            
            let nav = UINavigationController(rootViewController: oauthVC)
            
            presentViewController(nav, animated: true, completion: nil)
            
        }
    }
    
    